package com.ie.service.impl;

import com.ie.common.http.Result;
import com.ie.entity.Like;
import com.ie.mapper.LikeMapper;
import com.ie.service.LikeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class LikeServiceImpl implements LikeService {
    @Resource
    private LikeMapper likeMapper;

    @Override
    public Like likeCommunity(String userid, String likeid) {
        Like like= likeMapper.likeCommunity(userid, likeid);

        if ( like!= null) {
             //点赞数-1
            likeMapper.jian(likeid);
            likeMapper.down(userid, likeid);

            return like;
        }else{
            //点赞数+1
            likeMapper.jia(likeid);
                likeMapper.up(userid, likeid);
                return null;
            }

    }

    @Override
    public Result findLike(String userid) {
        return Result.build(likeMapper.findLike(userid),1, "成功");
    }

    @Override
    public void jia(String cid) {
         likeMapper.zhuanfa(cid);
    }
}
